//
//  HJSettlementRepairPartsViewCell.m
//  GAMCAfterSales
//
//  Created by 贺佳 on 2018/5/17.
//  Copyright © 2018年 glendale. All rights reserved.
//

#import "HJSettlementRepairPartsViewCell.h"

@interface HJSettlementRepairPartsViewCell()
/**
 收费区分字典
 */
@property(nonatomic,strong)NSMutableDictionary*priceDict;
@end
@implementation HJSettlementRepairPartsViewCell

UITablecellM(@"HJSettlementRepairPartsViewCell")
-(NSDictionary *)priceDict
{
    if (!_priceDict) {
        NSArray*ary=[self readershuDICimform][@"TM_CHARGE_PARTITION"];
        _priceDict=[NSMutableDictionary dictionary];
        for (NSDictionary*dict in ary) {
            _priceDict[dict[@"CODE"]]=dict[@"NAME"];
        }
    }
    return _priceDict;
}
-(NSMutableDictionary *)readershuDICimform
{
    NSMutableDictionary *dic=[NSMutableDictionary dictionary];
    NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *path=[paths objectAtIndex:0];
    NSString *str=[path stringByAppendingPathComponent:@"Dic.text"];
    dic=[NSMutableDictionary dictionaryWithContentsOfFile:str];
    //nslog(@"%@",dic);
    return dic;
}
-(void)setUI{
    self.selectionStyle=UITableViewCellSelectionStyleNone;
    for (int i=0; i<10; i++) {
        UILabel *titlelabel = [[UILabel alloc]init];
        titlelabel.backgroundColor = [UIColor clearColor];
        titlelabel.textColor = [UIColor grayColor];
        titlelabel.numberOfLines=0;
        titlelabel.font = [UIFont fontWithName:@"ArialMT" size:14];
        [titlelabel setTextAlignment:NSTextAlignmentCenter];
        [self.contentView addSubview:titlelabel];
        titlelabel.userInteractionEnabled=YES;
    }
}
-(void)setRepairSettlementPairListModel:(HJRepairSettlementPairListModel *)repairSettlementPairListModel
{
    _repairSettlementPairListModel=repairSettlementPairListModel;
    int i =0;
    for (UILabel*label in self.contentView.subviews) {
        switch (i) {
            case 0:
                
                break;
            case 1:
                label.text=repairSettlementPairListModel.PART_NO;
                break;
            case 2:
                label.text=repairSettlementPairListModel.PART_NAME;
                break;
            case 3:
                label.text=repairSettlementPairListModel.PART_QUANTITY;
                break;
            case 4:
            {
                NSString*price=self.priceDict[repairSettlementPairListModel.CHARGE_PARTITION_CODE];
                label.text=price.length?price:@"";
            }
               
                break;
            case 5:
                label.text=repairSettlementPairListModel.PART_SALES_PRICE;
                break;
            case 6:
            label.text=repairSettlementPairListModel.PART_SALES_AMOUNT;
                
                break;
            case 7:
            label.text=repairSettlementPairListModel.DISCOUNT;
                break;
            case 8:
            {
                float  amount=[repairSettlementPairListModel.PART_SALES_AMOUNT  floatValue];
                float discount=[repairSettlementPairListModel.DISCOUNT floatValue];
                float price=amount*(1-discount);
                label.text=[NSString stringWithFormat:@"%.2f",price];
            }
                break;
            case 9:
            {
                float  amount=[repairSettlementPairListModel.PART_SALES_AMOUNT  floatValue];
                float discount=[repairSettlementPairListModel.DISCOUNT floatValue];
                float price=amount*discount;
                label.text=[NSString stringWithFormat:@"%.2f",price];
            }

                break;
                
                
            default:
                break;
        }
        i++;
    }
}
-(void)setIndePath:(NSIndexPath *)indePath
{
    _indePath=indePath;
    UILabel*label=self.contentView.subviews[0];
    label.text=[NSString stringWithFormat:@"%zd",indePath.row+1];
}
-(void)layoutSubviews
{
    [super layoutSubviews];
    CGFloat w=self.contentView.mj_w/self.contentView.subviews.count;
    int i=0;
    for (UIView*subView in self.contentView.subviews) {
        subView.frame=CGRectMake(i*w, 0, w, self.contentView.mj_h);
        i++;
    }
}

@end
